"""
-*- coding: utf-8 -*-
@Time : 2021/9/24 0:27
@Author : chenke
@File : logs.py
"""

import logging
import os
import datetime
from utils.base_path import root_dir


def logger(filename):

    logger = logging.getLogger()

    logger.setLevel(level="DEBUG")
    formatter = logging.Formatter(fmt="%(name)s-->%(asctime)s-->%(levelname)s--->%(message)s")

    console_haddler = logging.StreamHandler()
    console_haddler.setFormatter(fmt=formatter)
    console_haddler.setLevel(level="DEBUG")


    now_time = datetime.datetime.now().strftime('%Y-%m-%d-%H')
    # path_file = root_dir + r'\log\{}_{}.log'.format(filename, now_time).replace(r'\/'.replace(os.sep, ''), os.sep)

    path_file = root_dir+"/log/{}_{}.log".format(filename,now_time)
    file_haddler = logging.FileHandler(path_file,"a",encoding="utf-8")
    file_haddler.setFormatter(fmt=formatter)
    file_haddler.setLevel(level="DEBUG")

    logger.addHandler(console_haddler)
    logger.addHandler(file_haddler)

    return logger

logger = logger("app")

print("===============")
print(root_dir)

print(os.path.abspath(os.path.realpath(__file__)))
